package yx.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import yx.dao.BaseDaoInt;
import yx.model.BsConfig;

@Service("configService")
public class ConfigServiceImpl implements ConfigServiceInt {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(ConfigServiceImpl.class);

	private BaseDaoInt<BsConfig> configDao;

	public BaseDaoInt<BsConfig> getConfigDao() {
		return configDao;
	}

	@Autowired
	public void setConfigDao(BaseDaoInt<BsConfig> configDao) {
		this.configDao = configDao;
	}

	@Override
	public List<BsConfig> getRefTable() {
		String hql = "from BsConfig t";
		List<BsConfig> list = configDao.find(hql);

		if (list != null && list.size() != 0) {
			return list;
		}
		return null;
	}

	@Override
	public Boolean isRefTable(Integer id, String tableName, String fieldName) {
		Boolean ret = false;
		String hql = "from " + tableName + " t where t." + fieldName + " = :fieldValue";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fieldValue", id);
		List<BsConfig> l = configDao.find(hql, params);
		if (l != null && l.size() != 0) {
			ret = true;
		}
		return ret;
	}

}
